package com.aacar.op.utils.pojo.easyui;

import com.github.pagehelper.PageInfo;
import org.springframework.data.domain.Page;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class DataGridResult<T> implements Serializable {
    private Long total;
    private List<T> rows = new ArrayList();

    public DataGridResult() {
    }

    public DataGridResult(Long total, List<T> rows) {
        this.total = total;
        this.rows = rows;
    }

    public DataGridResult(Page<T> page) {
        this.total = Long.valueOf(page.getTotalElements());
        this.rows = page.getContent();
    }

    public DataGridResult(PageInfo<T> pageInfo) {
        this.total = pageInfo.getTotal();
        this.rows = pageInfo.getList();
    }

    public static <T> DataGridResult<T> build(Page<T> page) {
        return new DataGridResult<T>(page);
    }

    public static <T> DataGridResult<T> build(PageInfo<T> pageInfo) {
        return new DataGridResult<T>(pageInfo);
    }

    public Long getTotal() {
        return this.total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public List<T> getRows() {
        return this.rows;
    }

    public void setRows(List<T> rows) {
        this.rows = rows;
    }
}